//
//  MainListCell.m
//  testTableView
//
//  Created by LYJ on 2019/9/20.
//  Copyright © 2019 LYJ. All rights reserved.
//

#import "MainListCell.h"
#import "Masonry.h"
#import "Configuration.h"

@implementation MainListCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style
              reuseIdentifier:(NSString *)reuseIdentifier
{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.headImv];
        [self.contentView addSubview:self.nameLabel];
        [self.contentView addSubview:self.introduceLabel];
        [self.contentView addSubview:self.lineLabel];
        [self viewsLayout];
    }
    return self;
}

#pragma mark - getters
- (UIImageView *)headImv {
    if (!_headImv)
    {
        _headImv = [[UIImageView alloc] init];
        _headImv.contentMode = UIViewContentModeScaleAspectFill;
        _headImv.layer.cornerRadius = 33/2.0;
        _headImv.layer.masksToBounds = YES;
        _headImv.image = [UIImage imageNamed:@"avatar_placeHolder"];
    }
    return _headImv;
}

- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] init];
        _nameLabel.font = [UIFont fontWithName:@"Verdana-Bold" size:17];
    }
    return _nameLabel;
}

- (UILabel *)introduceLabel {
    if (!_introduceLabel) {
        _introduceLabel = [[UILabel alloc] init];
        _introduceLabel.font = [UIFont fontWithName:@"Verdana" size:14];
        _introduceLabel.translatesAutoresizingMaskIntoConstraints = NO;
        _introduceLabel.lineBreakMode = NSLineBreakByTruncatingTail;
        _introduceLabel.numberOfLines = 0;
        _introduceLabel.textAlignment = NSTextAlignmentLeft;
    }
    return _introduceLabel;
}

- (UILabel *)lineLabel {
    if (!_lineLabel) {
        _lineLabel = [[UILabel alloc] init];
        _lineLabel.backgroundColor = [UIColor lightGrayColor];
    }
    return _lineLabel;
}
#pragma mark - layout

- (void)viewsLayout{
    [self.headImv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.contentView).mas_offset(WIDTH_PRO(10));
        make.width.height.mas_equalTo(WIDTH_PRO(33));
//        make.centerY.mas_equalTo(self.contentView);
        make.top.mas_equalTo(self.contentView).mas_offset(WIDTH_PRO(5));
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView);
        make.height.mas_equalTo(WIDTH_PRO(25));
        make.left.mas_equalTo(self.headImv.mas_right).mas_offset(WIDTH_PRO(5));
        make.right.mas_equalTo(self.contentView).mas_offset(WIDTH_PRO(-10));
    }];
    [self.introduceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.nameLabel.mas_bottom);
        make.bottom.mas_equalTo(self.contentView).mas_offset(HEIGHT_PRO(-5));
        make.left.right.mas_equalTo(self.nameLabel);
    }];
    [self.lineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.right.left.mas_equalTo(self.contentView);
        make.height.equalTo(@1);
    }];
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
